import Vue from 'vue';
import Router from 'vue-router';

const _import = require('./_import_' + process.env.NODE_ENV);

/* layout */
import Layout from '../views/layout/Layout';

/* login */
const Login = _import('login/index');

/* dashboard */
const dashboard = _import('dashboard/index');

/* error page */
const Err404 = _import('404');

const CourseList = _import('course/list');
const CourseEdit = _import('course/edit');

const AudioList = _import('audio/list');
const AudioEdit = _import('audio/edit');
const AudioBatch = _import('audio/batch');

const CategoryList = _import('category/list');
const CategoryEdit = _import('category/edit');

const SourceList = _import('source/list');
const SourceEdit = _import('source/edit');

const AuthorList = _import('author/list');
const AuthorEdit = _import('author/edit');

const RecommendList = _import('recommend/list');
const RecommendEdit = _import('recommend/edit');

const StatUserList = _import('statuser/list');
const StatUserDetail = _import('statuser/detail');

const StatOrderList = _import('statorder/list');
const StatOrderDetail = _import('statorder/detail');

const StatGrowList = _import('statgrow/list');

const StatCourseList = _import('statcourse/list');
const StatCourseDetail = _import('statcourse/detail');

const ChangePwd = _import('login/changepwd');

const AdminList = _import('admin/list');
const AdminEdit = _import('admin/edit');
const AdminAdd = _import('admin/add');

Vue.use(Router);

/**
 * icon : the icon show in the sidebar
 * hidden : if `hidden:true` will not show in the sidebar
 * redirect : if `redirect:noredirect` will not redirct in the levelbar
 * noDropdown : if `noDropdown:true` will not has submenu in the sidebar
 * meta : `{ role: ['admin'] }`  will control the page role
 **/
export const constantRouterMap = [
    { path: '/login', component: Login, hidden: true },
    { path: '/404', component: Err404, hidden: true },
    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        name: 'Home',
        hidden: true,
        children: [{ path: 'dashboard', component: dashboard }]
    }
]

export default new Router({
    // mode: 'history', //后端支持可开
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
});

export const asyncRouterMap = [
    {
        path: '/admin',
        component: Layout,
        redirect: '/admin/index',
        name: '管理员',
        noDropdown: true,
        icon: 'quanxian',
        meta: { role: ['admin'] },
        children: [
            { path: 'index', component: AdminList, name: '权限管理', icon: 'quanxian' },
            { path: 'add', component: AdminAdd, name: '新增管理员', icon: 'quanxian' },
            { path: 'update/:id', component: AdminEdit, name: '编辑管理员', icon: 'quanxian' }
        ]
    },
    {
        path: '/course',
        component: Layout,
        redirect: '/course/index',
        name: '课程管理',
        noDropdown: true,
        icon: 'zujian',
        meta: { role: ['operator'] },
        children: [
            { path: 'index', component: CourseList, name: '课程列表', icon: 'zonghe' },
            { path: 'add', component: CourseEdit, name: '新建课程', icon: 'zonghe' },
            { path: 'update/:id', component: CourseEdit, name: '编辑课程', icon: 'zonghe' },
            { path: 'audio/index/:courseId', component: AudioList, name: '音频列表', icon: 'zonghe' },
            { path: 'audio/add/:courseId', component: AudioEdit, name: '新建音频', icon: 'zonghe' },
            { path: 'audio/update/:audioId', component: AudioEdit, name: '编辑音频', icon: 'zonghe' },
            { path: 'audio/batch/:courseId', component: AudioBatch, name: '批量编辑', icon: 'zonghe' }
        ]
    },
    {
        path: '/category',
        component: Layout,
        redirect: '/category/index',
        name: '分类管理',
        noDropdown: true,
        icon: 'zujian',
        meta: { role: ['operator'] },
        children: [
            { path: 'index', component: CategoryList, name: '分类列表', icon: 'zonghe' },
            { path: 'add', component: CategoryEdit, name: '新建分类', icon: 'zonghe' },
            { path: 'update/:id', component: CategoryEdit, name: '编辑分类', icon: 'zonghe' }
        ]
    },
    {
        path: '/source',
        component: Layout,
        redirect: '/source/index',
        name: '内容源管理',
        noDropdown: true,
        icon: 'zujian',
        meta: { role: ['operator'] },
        children: [
            { path: 'index', component: SourceList, name: '内容源列表', icon: 'zonghe' },
            { path: 'add', component: SourceEdit, name: '新建内容源', icon: 'zonghe' },
            { path: 'update/:id', component: SourceEdit, name: '编辑内容源', icon: 'zonghe' }
        ]
    },
    {
        path: '/author',
        component: Layout,
        redirect: '/author/index',
        name: '作者管理',
        noDropdown: true,
        icon: 'zujian',
        meta: { role: ['operator'] },
        children: [
            { path: 'index', component: AuthorList, name: '作者列表', icon: 'zonghe' },
            { path: 'add', component: AuthorEdit, name: '新建作者', icon: 'zonghe' },
            { path: 'update/:id', component: AuthorEdit, name: '编辑作者', icon: 'zonghe' }
        ]
    },
    {
        path: '/recommend',
        component: Layout,
        redirect: '/recommend/index',
        name: 'banner',
        noDropdown: true,
        icon: 'zujian',
        meta: { role: ['operator'] },
        children: [
            { path: 'index', component: RecommendList, name: '管理banner', icon: 'zonghe' },
            { path: 'add', component: RecommendEdit, name: '新建banner', icon: 'zonghe' },
            { path: 'update/:id', component: RecommendEdit, name: '编辑banner', icon: 'zonghe' }
        ]
    },
    {
        path: '/statuser',
        component: Layout,
        redirect: '/statuser/index',
        name: '用户管理',
        noDropdown: true,
        icon: 'tubiaoleixingzhengchang',
        meta: { role: ['statistics'] },
        children: [
            { path: 'index', component: StatUserList, name: '用户列表', icon: 'tubiaoleixingzhengchang' },
            { path: 'detail/:id', component: StatUserDetail, name: '用户资料', icon: 'tubiaoleixingzhengchang' }
        ]
    },
    {
        path: '/statorder',
        component: Layout,
        redirect: '/statorder/index',
        name: '订单管理',
        noDropdown: true,
        icon: 'tubiaoleixingzhengchang',
        meta: { role: ['statistics'] },
        children: [
            { path: 'index', component: StatOrderList, name: '订单列表', icon: 'tubiaoleixingzhengchang' },
            { path: 'detail/:id', component: StatOrderDetail, name: '订单详情', icon: 'tubiaoleixingzhengchang' }
        ]
    },
    {
        path: '/statgrow',
        component: Layout,
        redirect: '/statgrow/index',
        name: '统计菜单',
        noDropdown: true,
        icon: 'tubiaoleixingzhengchang',
        meta: { role: ['statistics'] },
        children: [
            { path: 'index', component: StatGrowList, name: '增长统计', icon: 'tubiaoleixingzhengchang' }
        ]
    },
    {
        path: '/statcourse',
        component: Layout,
        redirect: '/statcourse/index',
        name: '统计课程',
        noDropdown: true,
        icon: 'tubiaoleixingzhengchang',
        meta: { role: ['statistics'] },
        children: [
            { path: 'index', component: StatCourseList, name: '课程访问量', icon: 'tubiaoleixingzhengchang' },
            { path: 'detail/:id', component: StatCourseDetail, name: '单个课程访问', icon: 'tubiaoleixingzhengchang' }
        ]
    },
    {
        path: '/common',
        component: Layout,
        redirect: '/common/changepwd',
        name: '通用',
        noDropdown: true,
        hidden: true,
        icon: 'zujian',
        children: [
            { path: 'changepwd', component: ChangePwd, name: '修改密码', icon: 'tubiaoleixingzhengchang' }
        ]
    },
    { path: '*', redirect: '/404', hidden: true }
];
